from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QPushButton, QMessageBox
import sys

# 装饰器信号与槽
# @PyQt5.QtCore.pyqtSlot(参数)
# def on_发送者对象名称_发射信号名称(self, 参数)：
#   pass
#
# 必须要先执行这行代码：QtCore.QMetaObject.connectSlotsByName(self)

class CustWidget(QWidget):
    def __init__(self, parent=None):
        super(CustWidget, self).__init__(parent)
        self.setWindowTitle("装饰器信号与槽Demo")
        self.resize(350, 50)

        self.okButton = QPushButton("OK", self)

        # 使用setObjectName设置对象名称
        self.okButton.setObjectName("okButton")
        layout = QHBoxLayout()
        layout.addWidget(self.okButton)
        self.setLayout(layout)

        QtCore.QMetaObject.connectSlotsByName(self)


    @QtCore.pyqtSlot()
    def on_okButton_clicked(self):
        print("单击了OK按钮")
        QMessageBox.information(self, "信息提示框", "单击了OK按钮")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = CustWidget()
    win.show()
    sys.exit(app.exec_())
